//提现流水列表 0

define(function(require, exports, module){
	"require:nomunge,exports:nomunge,module:nomunge";
	//异步请求
var wind_async=require('ddf_wind_async');
	
var base=require('component-base');
	
var history=require('component-history');

require('component-page');


var pageIndex=0;

var beginDate,endDate,beginMoney,endMoney,bankname;

var selectSettleApplyId;

var tips_index=0;


/**
 * 初始化参数
 */
function initParams(){
	
	
	beginDate="";
	endDate="";
	beginMoney="";
	endMoney="";
	bankName="";
	
}

/**
 * 查询提现流水列表
 */
exports.init=function(m){
	history.addHis(this,arguments);//增加历史
    window.$ddf_withdrawSettle = m;
	
		initParams();
		
		var htmlStr = "";


		htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">提现流水管理</a></div></div>';
		htmlStr += '<div class="container-fluid">';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span12">';
		htmlStr += '<div id="alert-tips0" ></div>';
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"><span class="icon"><i class="icon-search"></i></span><h5>搜索条件</h5><button type="button" class="label label-success toggle">缩放</button></div>  ';
		htmlStr += '<div class="widget-content nopadding">';
		htmlStr += '<form class="form-horizontal">';
		
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">申请时间：</label><div class="controls"><input class="span4 m-wrap Wdate" type="text" id="beginDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap Wdate" type="text" id="endDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) /></div></div></div>';
		
		htmlStr += '<div class="span6">';
    	htmlStr += '</div>';
		
    	htmlStr += '</div>';
    	
    	htmlStr += '<div class="row-fluid">';
    	
    	htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">金额：</label><div class="controls"><input class="span4 m-wrap" type="text" id="beginMoney" />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap" type="text" id="endMoney" /></div></div></div>';
		
    	htmlStr += '<div class="span6">';
    	htmlStr += '<div class="control-group">';
    	htmlStr += '<label class="control-label">银行名称：</label>';
    	htmlStr += '<div class="controls">';
    	htmlStr += '<input class="span8 m-wrap" type="text" id="bankName"/>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	
    	htmlStr += '</div>';
    	

    	htmlStr += '<div class="form-actions">';
		htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_withdrawSettle.searchSettle()">搜索</button>';
		htmlStr += ' <button class="btn btn-info" type="button" onClick="$ddf_withdrawSettle.resetSearchParams()">重置</button>';
		htmlStr += '</div>        ';
		htmlStr += '</form>';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
		htmlStr += '<h5>提现流水列表</h5>';
		htmlStr += '</div>';
		htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
		htmlStr += '<table class="table table-bordered data-table">';
		htmlStr += '<thead>';
		htmlStr += '<tr>';
		htmlStr += '<th>序号</th>';
//		htmlStr += '<th>账户</th>';
//		htmlStr += '<th>姓名</th>';
		htmlStr += '<th>申请方式</th>';
		htmlStr += '<th>申请时间</th>';
		htmlStr += '<th>金额</th>';
		htmlStr += '<th>费用</th>';
		htmlStr += '<th>状态</th>';
		htmlStr += '<th>银行</th>';
		htmlStr += '<th>收款人</th>';
		htmlStr += '<th>尾号</th>';
		htmlStr += '<th>处理时间</th>';
		htmlStr += '</tr>';
		htmlStr += '</thead>';
		htmlStr += '<tbody id="settleList">';
		htmlStr += '</tbody>';
		htmlStr += '</table>';
		htmlStr += '<div id="footPageDiv0">';

		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>  ';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '</div> ';

		showDiv("content0");

		$("#content0").html(htmlStr);
		
		getSettleList(1,pageSize,beginDate,endDate,beginMoney,endMoney,bankName);

}


/**
 * 查询提现流水列表
 * @param pageNumber
 * @param username
 */
function getSettleList(pageNumber,pageSize,beginDate,endDate,beginMoney,endMoney,bankName){
	
	var params={
			"page.pageNumber":pageNumber,
			"page.pageSize":pageSize,
			"beginDate":beginDate,
			"endDate":endDate,
			"beginMoney":beginMoney,
			"endMoney":endMoney,
			"bankName":bankName
	        };
	
	

	base.showLoading();
	
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.withdraw.getQueryWithdrawSettleList,params));
		
		getSettleListCallBack(data);
		
	}))().start();


	
}

/**
 * 查询提现记录列表_回调函数
 */
function getSettleListCallBack(data){
	
	if(data["code"]==1){


	var htmlStr = "";

	for (var i = 0; i < data["settleListData"].length; i++) {

		htmlStr += '<tr>';
		htmlStr += '<td>' +getSequence(data["pageNumber"],i+1) + '</td>';
//		htmlStr += '<td>'+data["settleListData"][i]["USER_NAME"]+'</td>';
//		htmlStr += '<td>'+data["settleListData"][i]["REAL_NAME"]+'</td>';
		htmlStr += '<td>'+data["settleListData"][i]["APPLY_TYPE_NAME"]+'</td>';
		htmlStr += '<td>'+data["settleListData"][i]["COMMIT_TIME"]+'</td>';
		htmlStr += '<td>'+parseFloat(data["settleListData"][i]["AMOUNT"])+'</td>';
		htmlStr += '<td>'+parseFloat(data["settleListData"][i]["FEE"])+'</td>';
		htmlStr += '<td style="color:red;">'+data["settleListData"][i]["APPLY_STATUS_NAME"]+'</td>';
		htmlStr += '<td>'+data["settleListData"][i]["BANK_NAME"]+'</td>';
		htmlStr += '<td>'+data["settleListData"][i]["ACCOUNT_NAME"]+'</td>';
		htmlStr += '<td>'+data["settleListData"][i]["BANK_NUMBER"]+'</td>';
		htmlStr += '<td>'+data["settleListData"][i]["FINISH_TIME"]+'</td>';
		
		htmlStr += '</tr>';
	}

	$("#settleList").html(htmlStr);
	
	$('#footPageDiv0').ddf_pagination(data["pageSize"],data["pageNumber"],data["totalCount"],data["totalPage"],{  
		 
		 changePageCallback:function(pageSize,page){  
			 getSettleList(page,pageSize,beginDate,endDate,beginMoney,endMoney,bankName)

		 },
		 changePageSizeCallBack:function(pageSize){
			 getSettleList(1,pageSize,beginDate,endDate,beginMoney,endMoney,bankName)
     	 
		 } 
     }); 

	}else{
		
		 base.tips_error(data["message"]);
	}

	base.cancelLoading();
	
}

/**
 * 重置参数
 */
function resetSearchParams(){
	
	beginDate="";
	endDate="";
	beginMoney="";
	endMoney="";
	bankName="";
	
	$("#beginDate").val("");
	
	$("#endDate").val("");
	
	$("#beginMoney").val("");
	
	$("#endMoney").val("");
	
	$("#bankName").val("");
	
	
}


/**
 * 搜索提现记录
 */
function searchSettle(){
	
	
	beginDate=$("#beginDate").val();
	
	endDate=$("#endDate").val();
	
	beginMoney=$("#beginMoney").val();
	
	endMoney=$("#endMoney").val();
	
	bankName=$("#bankName").val();
	
	
	if(!base.checkDate(beginDate,endDate)){
		return;
	}
	
	if(!(beginMoney==""&&endMoney=="")){
		if(beginMoney==""){
			base.tips_error("开始金额不能为空");
			return;
		}
		if(endMoney==""){
			base.tips_error("结束金额不能为空");
			return;
		}
	}
	if(parseFloat(beginMoney)>parseFloat(endMoney)){
		base.tips_error("开始金额不能大于结束金额");
		return;
	}
    
	getSettleList(pageNumber,pageSize,beginDate,endDate,beginMoney,endMoney,bankName);
	
}




/**
 * 显示DIV
 */
function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
	
	if(block=="content0"){
		shopTypeId="";
	}
	

	
}




//暴露方法
exports.getSettleList=getSettleList;
exports.resetSearchParams=resetSearchParams;
exports.searchSettle=searchSettle;

exports.showDiv=showDiv;

})();